import 'package:path/path.dart' as path;
import 'dart:io';

import 'package:sgy_flutter/i18n/en.dart';

void main(List<String> arguments) async {
  final cur = path.dirname(Platform.script.path).substring(1);
  print('当前路径1: $cur');
  final root = Directory("/${cur}");
  final list = root.listSync(recursive: true);
  final chineseList = [];
  for (var fileSystemEntity in list){
    if (fileSystemEntity is File && !fileSystemEntity.path.contains("i18n")){
      // print(fileSystemEntity);
      final file = File(fileSystemEntity.path);
      final text = file.readAsStringSync();
      RegExp regExp = new RegExp(r'(".*?".tr)');
      Iterable<Match> matches = regExp.allMatches(text);
      for (var match in matches){
        // print(match.group(0));
        chineseList.add(match.group(0)?.replaceAll('".tr', "").replaceAll('"', ""));
      }

      regExp = new RegExp(r"('.*?'.tr)");
       matches = regExp.allMatches(text);
      for (var match in matches){
        // print(match.group(0));
        chineseList.add(match.group(0)?.replaceAll("'.tr", "").replaceAll("'", ""));
      }
    }
  }
  print(chineseList);
  final notI18n = [];
  for (var cnKey in chineseList){
    if (en.keys.contains(cnKey)){
      print("${cnKey}-${en[cnKey]}");
    }else{
      notI18n.add(cnKey);
    }

  }
  print("没有翻译");
  for (var h in notI18n){
    print(h);
  }
}